/*!
 * \file SymbolTable.h
 */
#ifndef _CSymbolTable_H_BFE14F1C_E6D7_47CA_A3F8_B9A2815890DC_INCLUDED_
#define _CSymbolTable_H_BFE14F1C_E6D7_47CA_A3F8_B9A2815890DC_INCLUDED_

#include <cassert>
#include <map>
#include <vector>

/*!
 * \brief таблица уникальных T
 */
template<typename T>
class CSymbolTable
{
  typedef std::map<T,int> CMap;
  CMap m_map;
  std::vector<typename CMap::iterator> m_v;

public:
  int put(const T& obj)
  {
    if(m_map.count(obj))
      return m_map.find(obj)->second;
    else
    {
      m_v.push_back(m_map.insert(std::make_pair(obj,m_v.size())).first);
      return m_v.size()-1;
    }
  }

  const T& get(int i) const
  {
    assert(i>=0 && i<m_v.size());
    return m_v[i]->first;
  }

};//class CSymbolTable

#endif // _CSymbolTable_H_BFE14F1C_E6D7_47CA_A3F8_B9A2815890DC_INCLUDED_
